home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / GRAPHICS / GIF2RPC.SPK / source / 16bpp_48bit / c / nearest < prev    next >
Text File  |  1995-10-16  |  1KB  |  62 lines

  1. /* nearest.c
  2.  * AUTHOR:      Cy Booker, cy@cheepnis.demon.co.uk
  3.  * LICENSE:     FreeWare, Copyright (c) 1995 Cy Booker
  4.  */
  5.  
  6. #include "internal.h"
  7.  
  8. #include <assert.h>
  9.  
  10. #include "OS:macros.h"
  11.  
  12.  
  13.  
  14. /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15.  */
  16.  
  17. extern bool process_gif_16bpp_nearest_48bit(
  18.                 const process_gif       *p) {
  19.   byte                  *rove;
  20.   bits                  dest;
  21.   int                   width;
  22.   int                   x, y;
  23.   const os_colour       *palette;
  24.   int                   line_length;
  25.   bits                  pixtrans[256];
  26.  
  27.   assert(p);
  28.   assert(p->pixel_width > 0);
  29.   assert(p->pixel_height > 0);
  30.   assert(p->in_palette.colours);
  31.   assert(p->in_palette.ncolours < COUNT(pixtrans));
  32.  
  33.   process_gif_calc_pixtrans(p, pixtrans);
  34.  
  35.   /*
  36.    * not we pre-load values from the process_gif array
  37.    * because it considerably helps the compiler produce better code
  38.    */
  39.   rove = p->buffer;
  40.   width = (p->pixel_width + 1) & ~1;
  41.   palette = p->in_palette.colours;
  42.   line_length = p->line_length;
  43.   
  44.   for (y= p->pixel_height - 1; (y >= 0); y--) {
  45.     for (x= width - 1; (x >= 0); x--) {
  46.       /*
  47.        * writing one 32-bit word is much faster than two 16-bit shorts
  48.        */
  49.       dest = pixtrans[rove[x]];
  50.       x--;
  51.       dest <<= 16;
  52.       dest |= pixtrans[rove[x]];
  53.       *(((int *)rove) + (((unsigned int)x) >> 1)) = dest;
  54.     }
  55.     rove += line_length;
  56.   }
  57.   return FALSE;
  58. }
  59.  
  60.  
  61.  
  62.